<template>
  <div class="typescript-modules">
    <el-tabs v-model="activeName.value" @tab-click="handleClick">
      <el-tab-pane
        :label="item.name"
        :name="item.level"
        v-for="(item, index) in typeScriptData.data"
        :key="index"
      >
        <component :is="activeName.value"></component>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { ref, reactive } from 'vue'
import { tstab, upDataTab } from '@/store/typescirpt'
export default {
  components: {},
  setup() {
    const typeScriptData = reactive({
      data: [
        { id: 0, level: 'tabFirst', name: 'TS前言' },
        { id: 1, level: 'tabSecond', name: '基础类型' },
        { id: 2, level: 'tabThird', name: '类型断言/类型守卫' },
      ],
    })
    let activeName = tstab
    function handleClick(key) {
      //防止刷新
      sessionStorage.setItem('typeScriptTab', key.props.name)
      upDataTab({
        value: key.props.name,
      })
    }
    return {
      handleClick,
      typeScriptData,
      activeName,
    }
  },
}
</script>

<style lang="scss" scoped>
.typescript-modules {
  min-width: 1200px;
  padding: 10px 30px 0 30px;
  box-sizing: border-box;
}
</style>